FROM golang:1.18 as builder

WORKDIR /go

ARG SERVICE_NAME=v8s-api
ARG binaryPath=''

COPY . .

# hadolint ignore=DL3003,SC2154
RUN export GOPATH=/usr/local/go && cd src/${SERVICE_NAME}/service && \
CGO_ENABLED=0 GOOS=linux go build -ldflags="-X 'main.version=$(date -u +"%Y-%m-%dT%H-%M-%SZ")'" -o "${WORKDIR:-/go}/target/application" ./cmd

FROM alpine:3.15
ARG binaryPath='/target/application'
ENTRYPOINT ["/usr/bin/application"]
# hadolint ignore=DL3018
RUN apk add --no-cache ca-certificates tzdata && update-ca-certificates

COPY --from=builder --chmod=555 ${WORKDIR:-/go}/${binaryPath} /usr/bin/application
